package com.example.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2023/4/23 10:53
 */
@Controller
public class TestController {
    /**
     * 请求转发 1 原始
     */
    @RequestMapping("/fd")
    public void fd(HttpServletRequest request , HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/hello.html").forward(request,response);
    }
    /**
     * 请求转发 2 设置
     */
    @RequestMapping("/fd1")
    public String fd1(){
        return "forward: /hello.html";
    }

    /**
     * 请求转发 3 不设置，默认也是请求转发
     */
    @RequestMapping("/fd2")
    public String fd2(){
        return "/hello.html";
    }

    /**
     * 重定向 1 原始
     */
    @RequestMapping("/rd")
    public void rd(HttpServletResponse response) throws IOException {
        response.sendRedirect("/hello.html");

    }
    /**
     * 重定向 2 设置
     */
    @RequestMapping("/rd1")
    public String rd1(){
        return "redirect:/hello.html";
    }
}
